package com.lanvideo.task;

import com.lanvideo.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 会话清理定时任务
 */
@Component
public class SessionCleanupTask {

    @Autowired
    private SessionService sessionService;

    /**
     * 每5分钟清理一次无效会话
     */
    @Scheduled(fixedRate = 300000) // 5分钟
    public void cleanupInvalidSessions() {
        try {
            sessionService.cleanupInvalidSessions();
        } catch (Exception e) {
            // 记录日志但不影响系统运行
            System.err.println("清理无效会话时发生错误: " + e.getMessage());
        }
    }
}
